import os
import Models
import time
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from datetime import datetime


class MainPage(webapp.RequestHandler):
    
    def get(self):
        FillEmail(self)
        
def FillEmail(self):
    user = users.get_current_user()
    if user:
        self.response.headers['Content-Type'] = 'text/html'
    else:
        self.redirect(users.create_login_url(self.request.uri))
        
    gasticsModel = db.GqlQuery("SELECT * FROM GasticsModel WHERE User = :author", author=user)
    for gsModel in gasticsModel:
        gsModel.Email = user.email()
        gsModel.put()
        
application = webapp.WSGIApplication([('/fillemail', MainPage)],debug=True)
        
def main():
    run_wsgi_app(application)
if __name__ == "__main__":
    main()
